package com.example.design;

import com.example.design.abstractfactory.SkinFactory;
import com.example.design.abstractfactory.SpringButton;
import com.example.design.abstractfactory.SpringSkinFactory;
import com.example.design.adapter.ScoreOperation;
import com.example.design.bridge.Image;
import com.example.design.bridge.ImageImpl;
import com.example.design.bridge.PNGImage;
import com.example.design.bridge.WindowsImpl;
import com.example.design.builder.Actor;
import com.example.design.builder.ActorBuilder;
import com.example.design.builder.ActorController;
import com.example.design.builder.Builder;
import com.example.design.builder.ConcreteBuilder;
import com.example.design.builder.Director;
import com.example.design.builder.Product;
import com.example.design.facade.EncryptFacade;
import com.example.design.utils.XMLUtils;

public class Client {

	public static void maina(String[] args) {
		// TODO Auto-generated method stub
		//abstractfactory
		SkinFactory factory = new SpringSkinFactory();
		SpringButton springButton = (SpringButton) factory.createButton();
		springButton.display();
		
		//adapter
		ScoreOperation operation;
		try {
			operation = (ScoreOperation)(Class.forName((String)XMLUtils.getBean("src/adapterconfig.xml", "className"))).newInstance();
			int[] array = {2,6,3,9,5,8,1,0,11,1,54,23,778,99,3211};
			int target = 1;
			for(int i : operation.sort(array)){
				System.out.print(i + "  ");
			}
			System.out.println();
			System.out.println(operation.search(operation.sort(array), target));
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//bridge
		Image image = new PNGImage();
		ImageImpl impl = new WindowsImpl();
		image.setImageImpl(impl);
		image.parseFile("file");
		
		//Builder
		Builder builder = new ConcreteBuilder();
		Director director = new Director(builder);
		Product product = director.construct();
		ActorBuilder actorBuilder  = (ActorBuilder)XMLUtils.getBean("config.xml","className");
		
		ActorController actorController = new ActorController();
		Actor actor = actorController.construct(actorBuilder);
		System.out.println(actor.getType());
		System.out.println(actor.getSex());
		System.out.println(actor.getFace());
		System.out.println(actor.getCostume());
		System.out.println(actor.getHairstyle());
		
		//facade sample
		System.out.println("facade sample begin");
		EncryptFacade ef = new EncryptFacade();
		ef.FileEncrypt("src.txt", "dst.txt");
	}

}
